package com.asp.alumnisystem.adapter;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.asp.alumnisystem.R;
import com.asp.alumnisystem.base.IRefreshView;
import com.asp.alumnisystem.model.ForumModel;
import com.asp.alumnisystem.ui.DetailsActivity;
import com.asp.alumnisystem.utils.TimeUtils;
import com.asp.alumnisystem.utils.UiUtils;
import com.bumptech.glide.Glide;

/**
 * 首页论坛列表展示论坛信息的adapter
 */
public class ForumListAdapter extends AspBaseAdapter<ForumModel> {

    public ForumListAdapter(IRefreshView refreshView) {
        super(refreshView);
    }

    @Override
    protected int getItemLayoutId(int type) {
        return R.layout.forum_list_item_layout;
    }

    @Override
    protected void bindView(RViewHolder viewHolder, int position, final ForumModel model) {
        viewHolder.setText(R.id.forum_content, model.getContent());
        viewHolder.setText(R.id.author_name, model.getAuthorInfo().getNickName());
        viewHolder.setText(R.id.create_time, TimeUtils.longTime2String(model.getCreateTime(), TimeUtils.timePattern3));
        Glide.with(viewHolder.itemView.getContext()).load(model.getAuthorInfo().getIconPath()).into((ImageView) viewHolder.getView(R.id.author_icon));

        viewHolder.setItemOnClick(viewHolder.itemView, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putSerializable("model", model);
                UiUtils.jumpToPage(v.getContext(), DetailsActivity.class, bundle);
            }
        });

    }
}
